fix: change release sorting from CreatedAt to Id#692
fix: change release sorting from CreatedAt to Id#692louis1706 merged 2 commits intoExMod-Team:devfrom
Conversation
|
Just to double check, the IDs for releases will always be ascending? (newer releases have higher IDs?) |
|
According to https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-the-latest-release
So, created_at effectively references the timestamp of the commit used for the release. In theory, this should work fine for EXILED, but as we can see, it does not. import requests
URL = "https://api.github.com/repos/ExMod-Team/EXILED/releases"
HEADERS = {"Accept": "application/vnd.github+json"}
releases = requests.get(URL, headers=HEADERS).json()
# take newest 5 releases as returned by GitHub
latest_5 = releases[:5]
# sort by creation date (newest first)
by_created = sorted(
latest_5,
key=lambda r: r["created_at"],
reverse=True
)
# sort by GitHub release ID (highest first)
by_id = sorted(
latest_5,
key=lambda r: r["id"],
reverse=True
)
by_published = sorted(
latest_5,
key=lambda r: r["published_at"],
reverse=True
)
print("Newest by creation date:", by_created[0]["tag_name"])
print("Newest by id:", by_id[0]["tag_name"])
print("Newest by publish date:", by_published[0]["tag_name"])I wrote this quick Python script to compare the different sorting approaches:
I cannot find any documentation from GitHub explaining how this ID is generated. However, sorting by published_at seems to be the better approach here. Since the latest published release by a maintainer should always represent the most recent EXILED version users are expected to install, this appears to be the most reliable metric. |
Co-authored-by: AlexInABox <36812824+AlexInABox@users.noreply.github.com>
Description
Describe the changes
Releases are now sorted by their God (GitHub) given Id in descending order instead of by their creation time.
What is the current behavior? (You can also link to an open issue here)
What is the new behavior? (if this is a feature change)
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
Other information:
Types of changes
Submission checklist
Patches (if there are any changes related to Harmony patches)
Other